package com.hjm.project.system.job.task;

import com.hjm.common.utils.StringUtils;
import com.hjm.project.agentInfo.AgentCountData.service.AgentCountDataService;
import com.hjm.project.statistical.snCountData.service.ISnCountDataService;
import com.hjm.project.statistical.standard.service.IAgentMonthStandardService;
import com.hjm.project.system.sysConfigJob.domain.SysConfigJob;
import com.hjm.project.system.sysConfigJob.service.ISysConfigJobService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务调度类
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {

    /**
     * 每日交易总额 key
     */
    private static final String DAY_SUM_MONEY = "day_sum_money";

    /**
     * 每月升档操作
     */
    private static final String AGENT_GRADE_UPGRADE = "agent_grade_upgrade";

    /**
     * 统计已达标台均
     */
    private static final String AGENT_MONTH_SUM = "agent_month_sum";

    /**
     * 终端月交易总额
     */
    private static final String SN_COUNT_DATA = "sn_count_data";


    @Resource
    private AgentCountDataService agentCountDataService;    //数据统计

    @Resource
    private ISysConfigJobService iSysConfigJobService;     //定时任务参数

    @Resource
    private ISnCountDataService iSnCountDataService;

    @Resource
    private IAgentMonthStandardService agentMonthStandardService;   //达标台均

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {

        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }


    /**
     * 所有代理的每日交易汇总统计
     * @Param []
     * @Return void
     */
    public void agentTradingAll(){
        String msg = "统计成功";
        SysConfigJob sysConfigJob = iSysConfigJobService.beginSysConfigJob(DAY_SUM_MONEY);
        try {
            agentCountDataService.agentTradingAll(sysConfigJob);
        } catch (Exception e) {
            e.printStackTrace();
            msg = StringUtils.substring(e.getMessage(), 0, 2000);
        }
        iSysConfigJobService.endSysConfigJob(DAY_SUM_MONEY,msg);
    }

    /**
     * 统计个人档位
     * @Param []
     * @Return void
     */
    public void agentTradinMonth(){
        String msg = "统计成功";
        SysConfigJob sysConfigJob = iSysConfigJobService.beginSysConfigJob(AGENT_GRADE_UPGRADE);
        try {
            agentCountDataService.agentTradinMonth(sysConfigJob);
        } catch (Exception e) {
            e.printStackTrace();
            msg = StringUtils.substring(e.getMessage(), 0, 2000);
        }
        iSysConfigJobService.endSysConfigJob(AGENT_GRADE_UPGRADE,msg);
    }




    /**
     * 统计达标
     * @Param []
     * @Return void
     */
    public void selectMontSum(){
        String msg = "统计成功";
        SysConfigJob sysConfigJob = iSysConfigJobService.beginSysConfigJob(AGENT_MONTH_SUM);
        try {
            agentCountDataService.monthStandard(sysConfigJob);
        } catch (Exception e) {
            e.printStackTrace();
            msg = StringUtils.substring(e.getMessage(), 0, 2000);
        }
        iSysConfigJobService.endSysConfigJob(AGENT_MONTH_SUM,msg);

    }



    /**
     * sn月交易统计
     * @Param []
     * @Return void
     */
    public void snCountData() throws Exception {
        String msg = "统计成功";
        SysConfigJob sysConfigJob = iSysConfigJobService.beginSysConfigJob(SN_COUNT_DATA);
        try {
            iSnCountDataService.suCountDataSum(sysConfigJob);
        } catch (Exception e) {
            e.printStackTrace();
            msg = StringUtils.substring(e.getMessage(), 0, 2000);

        }
        iSysConfigJobService.endSysConfigJob(SN_COUNT_DATA,msg);
    }




}
